<?php

class ProjectHelper
{
	public static function canReadProject($project)
	{
		if (Yii::app()->user->isGuest)
		{
			return false;
		}
		
		if ($project->owner->adviser_initials == Yii::app()->user->getState('dbuser')->initials && Yii::app()->user->checkAccess('Adviser.canCreateProject'))
		{
			return true;
		}
		
		if (Yii::app()->user->checkAccess('Adviser.canAccessAllProjects'))
		{
			return true;
		}
		
		return false;
	}
	
	
	public static function canEditProject($project)
	{
		if (! self::canReadProject($project))
		{
			return false;
		}

		if ($project->owner->adviser_initials == Yii::app()->user->getState('dbuser')->initials && Yii::app()->user->checkAccess('Adviser.canCreateProject'))
		{
			
			return true;
		}
		
		if (Yii::app()->user->checkAccess('Adviser.canEditAllProjects'))
		{
			return true;
		}
		
		return false;
	}
	
}